<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
            <el-form-item>
                <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
                <el-button icon="Refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
            <!-- <el-col :span="1.5">
                <el-button type="primary" plain icon="Plus" @click="handleAdd"
                    v-hasPermi="['separate:account:add']">新增</el-button>
            </el-col> -->
            <!-- <el-col :span="1.5">
                <el-button type="success" plain icon="Edit" :disabled="single" @click="handleUpdate"
                    v-hasPermi="['separate:account:edit']">修改</el-button>
            </el-col> -->
            <!-- <el-col :span="1.5">
                <el-button type="danger" plain icon="Delete" :disabled="multiple" @click="handleDelete"
                    v-hasPermi="['separate:account:remove']">删除</el-button>
            </el-col> -->
            <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="configList">
            <el-table-column label="微信实名" align="center" prop="wxRealName" />
            <el-table-column label="微信ID" align="center" prop="openId" />
            <!-- <el-table-column label="支付宝实名" align="center" prop="zfbRealName" /> -->
            <!-- <el-table-column label="支付宝ID" align="center" prop="zfbUserId" /> -->
            <el-table-column label="分账比例" align="center" prop="ratio" />
            <el-table-column label="收款账户" align="center" prop="receiveAccount">
                <template #default="scope">
                    <dict-tag :options="receive_account" :value="scope.row.receiveAccount" />
                </template>
            </el-table-column>
            <el-table-column label="操作" align="center" width="150" class-name="small-padding fixed-width">
                <template #default="scope">
                    <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)"
                        v-hasPermi="['separate:account:edit']">修改</el-button>
                    <!-- <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)"
                        v-hasPermi="['separate:account:remove']">删除</el-button> -->
                </template>
            </el-table-column>
        </el-table>

        <!-- 添加或修改参数配置对话框 -->
        <el-dialog :title="title" v-model="open" width="500px" append-to-body>
            <el-form ref="configRef" :model="form" :rules="rules" label-width="100px">
                <el-form-item label="微信实名" prop="wxRealName">
                    <el-input v-model="form.wxRealName" placeholder="请输入微信实名" />
                </el-form-item>
                <!-- <el-form-item label="微信ID" prop="openId">
                    <el-input v-model="form.openId" placeholder="请输入微信ID" />
                </el-form-item> -->
                <!-- <el-form-item label="支付宝实名" prop="zfbRealName">
                    <el-input v-model="form.zfbRealName" placeholder="请输入支付宝实名" />
                </el-form-item> -->
                <!-- <el-form-item label="支付宝ID" prop="zfbUserId">
                    <el-input v-model="form.zfbUserId" placeholder="请输入支付宝ID" />
                </el-form-item> -->
                <el-form-item label="分账比例" prop="ratio">
                    <el-input v-model="form.ratio" placeholder="请输入分账比例" />
                </el-form-item>
                <el-form-item label="收款账户" prop="receiveAccount">
                    <el-radio-group v-model="form.receiveAccount">
                        <el-radio v-for="dict in receive_account" :key="dict.value" :label="dict.value">{{ dict.label
                        }}</el-radio>
                    </el-radio-group>
                </el-form-item>
            </el-form>
            <template #footer>
                <div class="dialog-footer">
                    <el-button type="primary" @click="submitForm">确 定</el-button>
                    <el-button @click="cancel">取 消</el-button>
                </div>
            </template>
        </el-dialog>
    </div>
</template>
 
<script setup name="Separate">
import { listSeparate, getSeparate, delSeparate, addSeparate, updateSeparate } from "@/api/system/separate";

const { proxy } = getCurrentInstance();
const { receive_account } = proxy.useDict("receive_account");

const configList = ref([]);
const open = ref(false);
const loading = ref(true);
const showSearch = ref(true);
const ids = ref([]);
const single = ref(true);
const multiple = ref(true);
const title = ref("");
const dateRange = ref([]);

const data = reactive({
    form: {},
    queryParams: {
        pageNum: 1,
        pageSize: 10,
    },
    rules: {
        wxRealName: [{ required: true, message: "微信实名不能为空", trigger: "blur" }],
        openId: [{ required: true, message: "微信ID不能为空", trigger: "blur" }],
        // zfbRealName: [{ required: true, message: "支付宝实名不能为空", trigger: "blur" }],
        // zfbUserId: [{ required: true, message: "支付宝ID不能为空", trigger: "blur" }],
        ratio: [{ required: true, message: "分账比例不能为空", trigger: "blur" }],
        receiveAccount: [{ required: true, message: "收款账户不能为空", trigger: "blur" }],
    }
});

const { queryParams, form, rules } = toRefs(data);

/** 查询参数列表 */
function getList() {
    loading.value = true;
    listSeparate(proxy.addDateRange(queryParams.value, dateRange.value)).then(response => {
        configList.value = response.data;
        loading.value = false;
    });
}
/** 取消按钮 */
function cancel() {
    open.value = false;
    reset();
}
/** 表单重置 */
function reset() {
    form.value = {
        wxRealName: undefined,
        openId: undefined,
        zfbRealName: undefined,
        zfbUserId: undefined,
        ratio: undefined,
        receiveAccount: undefined
    };
    proxy.resetForm("configRef");
}
/** 搜索按钮操作 */
function handleQuery() {
    queryParams.value.pageNum = 1;
    getList();
}
/** 重置按钮操作 */
function resetQuery() {
    dateRange.value = [];
    proxy.resetForm("queryRef");
    handleQuery();
}
/** 新增按钮操作 */
function handleAdd() {
    reset();
    open.value = true;
    title.value = "添加参数";
}
/** 修改按钮操作 */
function handleUpdate(row) {
    reset();
    form.value = row;
    open.value = true;
    title.value = "修改参数";
}
/** 提交按钮 */
function submitForm() {
    proxy.$refs["configRef"].validate(valid => {
        if (valid) {
            if (form.value.separateId != undefined) {
                updateSeparate(form.value).then(response => {
                    proxy.$modal.msgSuccess("修改成功");
                    open.value = false;
                    getList();
                });
            } else {
                addSeparate(form.value).then(response => {
                    proxy.$modal.msgSuccess("新增成功");
                    open.value = false;
                    getList();
                });
            }
        }
    });
}
/** 删除按钮操作 */
function handleDelete(row) {
    const separateIds = row.separateId || ids.value;
    proxy.$modal.confirm('是否确认删除参数编号为"' + separateIds + '"的数据项？').then(function () {
        return delSeparate(separateIds);
    }).then(() => {
        getList();
        proxy.$modal.msgSuccess("删除成功");
    }).catch(() => { });
}

getList();
</script>
 